package org.bedracket.pgeg.network;

import net.minecraft.network.FriendlyByteBuf;
import net.minecraftforge.network.NetworkEvent;
import net.minecraftforge.network.NetworkRegistry;
import net.minecraftforge.network.simple.SimpleChannel;
import org.bedracket.pgeg.PGEGMod;
import org.bedracket.pgeg.util.Helpers;

import java.util.function.BiConsumer;
import java.util.function.Function;
import java.util.function.Supplier;

public class SimpleNetworkHandler {

    public static final SimpleChannel PACKET_HANDLER =
            NetworkRegistry.newSimpleChannel(Helpers.identifier("main"),
                    () -> PGEGMod.NETWORK_VERSION,
                    PGEGMod.NETWORK_VERSION::equals,
                    PGEGMod.NETWORK_VERSION::equals);

    public static int id = 0;

    public static <T> void registerMessage(Class<T> messageType, BiConsumer<T, FriendlyByteBuf> encoder, Function<FriendlyByteBuf, T> decoder, BiConsumer<T, Supplier<NetworkEvent.Context>> messageConsumer) {
        PACKET_HANDLER.registerMessage(id, messageType, encoder, decoder, messageConsumer);
        id++;
    }
}
